package test2;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;


public class test1 {
    public static void main(String[] args) {
        //原料1类加载器，负责加载*.class文件
        ClassLoader classLoader = test1.class.getClassLoader();

        //原料2接口信息,JDK根据此接口信息来动态创建代理对象
        DangDangBook dangDangBook = new DangDangBook();
        Class<?>[] interfaces = dangDangBook.getClass().getInterfaces();

        //原料3增强算法
        InvocationHandler invocationHandler = new MyInvocationHandler(dangDangBook);

//      静态代理  SFproxyBook sFproxy= new SFproxyBook(dangDang);

//      动态
        Object proxy = Proxy.newProxyInstance(classLoader,interfaces,invocationHandler);
        System.out.println(proxy.getClass().getInterfaces().length);
        System.out.println(proxy.getClass().getInterfaces()[0].getName());
        ISendBook sendBook = (ISendBook) proxy;
        sendBook.sendBook("中国",18);
    }

}
